home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / DCLAP 4j / DClap / DFile.h < prev    next >
Encoding:
Text File  |  1995-12-17  |  3.6 KB  |  113 lines  |  [TEXT/R*ch]

  1. // DFile.h
  2.  
  3. #ifndef _DFILE_
  4. #define _DFILE_
  5.  
  6.  
  7. #include "DObject.h"
  8. #include "Dvibrant.h"
  9.  
  10.  
  11. class    DFileManager    : public    DObject
  12. {
  13.     static char    fName[640];
  14. public:
  15.     enum FileTypes { kNothing, kIsFile, kIsFolder };
  16.     static const char* kUntitled;
  17.     
  18.     static const char* GetInputFileName( const char* extension,  const char* mactype);
  19.     static const char* GetOutputFileName( const char* defaultname);        
  20.     static const char* GetFolderName();
  21.     static const char* GetProgramPath();
  22.     static const char* FilenameFromPath( const char* pathname);
  23.     static const char* PathOnlyFromPath( const char* pathname);
  24.     static char*    TempFilename( char* namestore = NULL);
  25.     static Boolean CreateFolder( const char* pathname);
  26.     static const char* BuildPath( const char* rootpath, const char* subfolder, 
  27.                                                     const char* filename = NULL);
  28.     static const char* FileSuffix( const char* pathname);
  29.     static void ReplaceSuffix( char* filename, long maxname, const char* suffix);
  30.     static Boolean FileExists( const char* pathname);
  31.     static short FileOrFolderExists( const char* pathname);
  32.     static void UnixToLocalPath( char*& pathname);
  33.     
  34. };
  35.  
  36. extern    DFileManager*        gFileManager;
  37.  
  38.  
  39.  
  40. class DFile : public DObject
  41. {
  42. public:    
  43.     FILE*    fFile;
  44.     char*    fName;
  45.     char*    fMode;
  46.     char* fType;
  47.     char* fSire;
  48.     Boolean fEof;
  49.     
  50.     DFile();
  51.     DFile(const char* filename, const char* openmode = "r",
  52.                 const char* ftype = NULL, const char* fcreator = NULL);
  53.     virtual ~DFile();
  54.     virtual    Boolean suicide(void);  // prefered to delete 
  55.     virtual    Boolean suicide(short ownercount);
  56.  
  57.     virtual void Initialize(const char* filename, const char* openmode = "r",
  58.                     const char* ftype = NULL, const char* fcreator = NULL);
  59.     virtual const char*    GetName() { return fName; }
  60.     virtual const char*    GetShortname() { return gFileManager->FilenameFromPath(fName); }
  61.     
  62.             // short result in most funcs here is error code or 0
  63.     virtual short Open(const char* openmode = NULL);
  64.     short OpenFile(const char* openmode = NULL) { return this->Open(openmode); }
  65.     virtual short Close();
  66.     short CloseFile() { return this->Close(); }
  67.     virtual short GetDataLength(ulong& filelen);
  68.     virtual short GetDataMark(ulong& fileindex);
  69.     ulong Tell() { ulong fileindex; GetDataMark( fileindex); return fileindex; }
  70.     ulong LengthF() { ulong filelen; GetDataLength( filelen); return filelen; }
  71.     virtual short SetDataMark(ulong fileindex);
  72.     short Seek(ulong fileindex) { return SetDataMark( fileindex); }
  73.     virtual Boolean Exists();
  74.     virtual Boolean EndOfFile();
  75.     Boolean Eof() { return EndOfFile(); }
  76.     virtual Boolean IsOpen() { return fFile != NULL; }
  77.     virtual void SetMode(const char* openmode);
  78.  
  79.     virtual Boolean Delete();
  80.     virtual Boolean Rename(const char* newname);
  81.     virtual void Create(const char* filetype, const char* creator);  // type,creator only honored on mac
  82.  
  83.     virtual short GetFileType(long& fileType);
  84.     virtual short ReadData( void* buffer, ulong& count);
  85.     virtual short ReadUntil( void* buffer, ulong& count, char stopchar);
  86.     virtual short ReadLine( char* line, ulong count);
  87.     virtual short WriteData( void* buffer, ulong& count);
  88.     virtual short WriteLine( char* line, Boolean addNewline= false);
  89.     short WriteLn( char* line) { return WriteLine( line, true); }
  90. };
  91.  
  92.  
  93.  
  94.     // DTempFile is mainly a quick hack till we get iostreams written into critical places
  95.     // use tempfile to write to then read back into memory:
  96.     //   DTempFile* tmp = new DTempFile();  
  97.     //   tmp->WriteLine(data); tmp->WriteLine(data); ...
  98.     //     ulong datasize;
  99.     //     char* data= tmp->ReadIntoMemory(datasize);
  100.     //     delete tmp;
  101.     
  102. class DTempFile : public DFile
  103. {
  104. public:
  105.     DTempFile();
  106.     virtual ~DTempFile(); // delete temp file
  107.     virtual char* ReadIntoMemory(ulong& bytesread, Boolean deleteAfterRead= true);
  108. };
  109.  
  110.  
  111.  
  112. #endif // _DFILE_
  113.